<template>
    <div>
        <div class="coupon-list-window td-fc" :class="{on: show}">
            <div class="title">
                优惠券
                <img :src="$global.Image.icon_close" @click="close">
            </div>
            <div class="doupon-scroll td-f1">
                <div class="coupon-list" v-if="couponList.length > 0">
                    <div class="item td-f" v-for="coupon in couponList" :key="coupon.id" @click="click(coupon)">
                        <div class="left td-f1">
                            <div class="money">
                                <span>￥<b class="num">{{ coupon.coupon_price }}</b></span>
                                <span class="pic-num">满{{ coupon.use_min_price }}元可用</span>
                            </div>
                            <div class="text">
                                <div class="condition ellipsis">
                                    <span class="line-title" v-if="coupon.type === 0">通用劵</span>
                                    <span class="line-title" v-else-if="coupon.type === 1">品类券</span>
                                    <span class="line-title" v-else>商品券</span>
                                    <span class="coupon-name">{{ coupon.title }}</span>
                                </div>
                                <div class="data">
                                    <div>
                                        {{ coupon.start_time ? coupon.start_time + "-" : ""
                    }}{{ coupon.end_time }}
                                    </div>
                                    <div class="iconfont" v-if="checked === coupon.id"></div>
                                    <div class="iconfont" v-else></div>
                                </div>
                            </div>
                        </div>
                        <div class="right td-fcc">
                            <span>立<br>即<br>使<br>用</span>
                        </div>
                        <div class="coupon-status"></div>
                    </div>
                </div>
                <div v-else class="pictrue td-fcc">
                    <img :src="$global.Image.noCoupon" class="image" />
                </div>
            </div>
            <div class="couponNo td-fcc" @click="couponNo">
                <el-button class="btn btn-r">不使用优惠券</el-button>
            </div>
        </div>
        <div class="mask" v-if="show"  @click="close"></div>
    </div>
</template>

<script>
import { getOrderCoupon } from "@api/order";

export default {
    name: "CouponListWindow",
    props: {
        cartid: {
            type: String,
            default: ""
        },
        price: {
            type: String,
            default: ""
        },
    },
    data() {
        return {
            show: false,
            couponList: []
        };
    },
    methods: {
        open () {
            this.show = true
            this.getCoupon()
        },
        close() {
            this.show = false
        },
        getCoupon() {
            let data = {
                cartId: this.cartid
            };
            getOrderCoupon(this.price, data)
                .then(res => {
                    this.couponList = res.data;
                })
                .catch(err => {
                    this.$dialog.error(err.msg);
                });
        },
        click(coupon) {
            this.$emit("checked", coupon);
            this.close()
        },
        couponNo() {
            this.$emit("checked", null);
            this.close()
        }
    }
};
</script>

<style scoped  lang="scss" scoped>
.coupon-list-window {
    position: fixed;
    top: 0;
    right: -100%;
    width: 300px;
    z-index: 1000;
    bottom: 0;
    background-color: #eee;
    border-left: solid #DA213D 5px;
    padding: 20px;
    transition: all .5s;
    .title{
        font-size: 16px;
        color: #333;
        margin-bottom: 20px;
        line-height: 1.2;
        padding-left: 10px;
        border-left: solid #e83323 4px;
        position: relative;
        img{
            position: absolute;
            display: block;
            width: 16px;
            height: 16px;
            top: 0;
            right: 0;
            cursor: pointer;
        }
    }
    .doupon-scroll{
        overflow-y: auto;
    }
    .pictrue{
        height: 100%;
        img{
            width: 80%;
        }
    }
    .coupon-list{
        .item{
            height: 240px;
            height: 118px;
            background-color: #fff;
            margin-bottom: 10px;
            border-radius: 2px;
            position: relative;
            .money{
                font-size: 16px;
                color: #e83323;
                padding: 10px 0 0 10px;
                .num{
                    font-size: 22px;
                }
            }
            .pic-num{
                font-size: 14px;
                padding-left: 10px;
            }
            .text{
                padding: 10px 0 0 10px;
                .coupon-name{
                    font-size: 15px;
                    padding-left: 10px;
                    color: #333;
                }
            }
            .data{
                font-size: 13px;
                color: #999;
                padding-top: 10px;
            }
            .coupon-status{
                position: absolute;
                right: 45px;
                bottom: 5px;
                width: 47px;
                height: 47px;
                background-image: url(../assets/img/bg-coupon.png);
                background-position: -59px 0;
            }
            .right{
                background-color: #74d2d4;
                background-image: url(../assets/img/bg-coupon.png);
                background-position: -236px -124px;
                width: 36px;
                cursor: pointer;
                .btn{
                    color: #fff;
                }
            }
        }
    }

}
.coupon-list-window.on {
    right: 0;
}
.couponNo {
    padding-top: 10px;
    .btn{
        width: 100%;
    }
}
.condition .line-title {
    width: 0.9rem;
    padding: 0 0.1rem;
    box-sizing: border-box;
    background: rgba(255, 247, 247, 1);
    border: 1px solid rgba(232, 51, 35, 1);
    opacity: 1;
    border-radius: 0.22rem;
    font-size: 0.2rem;
    color: #e83323;
    margin-right: 0.12rem;
}
.mask{
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 999;
}
</style>
